home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / sspell14.zip / UTILITY.C < prev    next >
C/C++ Source or Header  |  1992-07-09  |  4KB  |  138 lines

  1. /* **************************************************************** */
  2. /*             sspell - similar to Unix spell                       */
  3. /*                        version 1.4                               */
  4. /*                                                                  */
  5. /* Author: Maurice Castro                                           */
  6. /* Release Date:  4 Jul 1992                                         */
  7. /* Bug Reports: maurice@bruce.cs.monash.edu.au                      */
  8. /*                                                                  */
  9. /* This code has been placed by the Author into the Public Domain.  */
  10. /* The code is NOT covered by any warranty, the user of the code is */
  11. /* solely responsible for determining the fitness of the program    */
  12. /* for their purpose. No liability is accepted by the author for    */
  13. /* the direct or indirect losses incurred through the use of this   */
  14. /* program.                                                         */
  15. /*                                                                  */
  16. /* Segments of this code may be used for any purpose that the user  */
  17. /* deems appropriate. It would be polite to acknowledge the source  */
  18. /* of the code. If you modify the code and redistribute it please   */
  19. /* include a message indicating your changes and how users may      */
  20. /* contact you for support.                                         */
  21. /*                                                                  */
  22. /* The author reserves the right to issue the official version of   */
  23. /* this program. If you have useful suggestions or changes for the  */
  24. /* code, please forward them to the author so that they might be    */
  25. /* incorporated into the official version                           */
  26. /*                                                                  */
  27. /* Please forward bug reports to the author via Internet.           */
  28. /*                                                                  */
  29. /* **************************************************************** */
  30.  
  31. #include "utility.h"
  32. #include <stdio.h>
  33. #include "strfn.h"
  34.  
  35. char *strip(a,b)
  36. char *a;
  37. char *b;
  38. {
  39.     char *match;
  40.     char *pt;
  41.     /* if the string 'a' contains any of string 'b' then chop them off */
  42.     pt = a;
  43.     while (*pt != NULL)
  44.     {
  45.         match = b;
  46.         while (*match != NULL)
  47.         {
  48.             if (*match == *pt)
  49.             {
  50.                *pt = NULL;
  51.                return(a);
  52.                }
  53.             match++;
  54.             }
  55.         pt++;
  56.         }
  57.     return(a);
  58.     }
  59.  
  60. char *strltok(st,c,sthold)
  61. char *st;
  62. char *c;
  63. char **sthold;
  64. {
  65.     char *stpt;
  66.     char *sth;
  67.     char *cp;
  68.     int flag;
  69.     char ch;
  70.  
  71.     if ((st == NULL) && (**sthold == NULL)) return(NULL); 
  72.  
  73.     if (st != NULL)
  74.     {
  75.         *sthold = st; 
  76.     }
  77.  
  78.     /* skip leading */
  79.     stpt = *sthold;
  80.     while (*stpt)
  81.     {
  82.         cp = c;
  83.         flag = 1;
  84.         ch = *stpt;
  85.         while (*cp)
  86.         {
  87.             if (ch == *cp)
  88.                flag = 0;
  89.             cp++;
  90.             }
  91.         if (flag) break;
  92.         stpt++;
  93.         }
  94.  
  95.     if (*stpt == NULL) return(NULL);  /* hit end of string */
  96.  
  97.     sth = stpt;
  98.  
  99.     /* if trailing clobber and exit */
  100.     while (*sth) 
  101.     {
  102.         ch = *sth;
  103.         cp = c;
  104.         while (*cp)
  105.     {
  106.         if (ch == *cp)
  107.         {
  108.                 *sth = NULL;
  109.                 *sthold = ++sth;
  110.         return(stpt);
  111.         }
  112.         cp++;
  113.         }
  114.     sth++;    
  115.     }
  116.     *sthold = sth;
  117.     return(stpt);
  118.     }
  119.  
  120. /* some machines have difficulties with a NULL being presented as a string
  121.    to the string copy operation. This new function prevents the problem,
  122.    unfortunately it causes a minor performance loss - so it is only used
  123.    in the root routine where the problem has been observed */
  124.  
  125. char *lstrcpy(s, ct)               /* the requirement for this check */
  126. char *s;                           /* was found by Mike O'Carroll */
  127. char *ct;                          /* M. Castro 4/3/92 */
  128. {
  129.      if (ct == NULL)
  130.      {
  131.          return(strcpy(s,""));
  132.          }
  133.      else
  134.      {
  135.          return(strcpy(s,ct));
  136.          }
  137.      }
  138.